<!--
 * @Author: your name
 * @Date: 2022-03-01 09:31:37
 * @LastEditTime: 2024-04-25 16:30:40
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \trace-source-web\src\views\trace-source-manage\traceability-information-supplement\index.vue
// 配置溯源码
-->
<template>
  <baseMainSlot :show-tab="true">
    <template v-slot:btn-box>
      <ActionBar
        :page-no="87"
        :add-active="addActive"
        :del-active="delActive"
        :edit-active="editActive"
        :has-cancel="false"
        :has-save="false"
        @add="add"
        @cancel="cancel('formData')"
        @edit="edit"
        @del="del"
        @save="save"
      />
    </template>
    <template v-slot:tab-select>
      <selectbutton
        :buttonselectlist="buttonselectlist"
        @nowselectbuttonindex="nowselectbuttonindex"
      />
    </template>
    <template v-slot:search-box>
      <SearchBox @search="search">
        <div class="common-search-item topview">
          <div class="label">溯源信息来源：</div>
          <div class="input">
            <el-select
              v-model="type"
              clearable
              filterable
              placeholder="请选择"
              @change="systemPathInfo"
            >
              <el-option
                v-for="(item, index) in systemPathList"
                :key="index"
                :label="item.name"
                :value="item.type"
              />
            </el-select>
          </div>
        </div>
        <div class="common-search-item">
          <div class="label">选择溯源范围：</div>
          <div class="input">
            <el-checkbox-group v-model="scopeSearch" @change="search()">
              <el-checkbox-button
                v-for="(city, index) in scopeList"
                :key="index"
                :label="city.type"
                :disabled="city.type === 'MACHINING' ? true : false"
              >{{ city.name }}</el-checkbox-button>
            </el-checkbox-group>
          </div>
        </div>
        <div v-if="systemPathStatus" class="common-search-item">
          <!-- <div class="common-search-item-title">选择溯源范围：</div> -->
          <el-select
            v-model="varietyName"
            class="input-select"
            filterable
            clearable
            placeholder="请选择种养品种"
            @change="productionBaselist($event, '品种')"
          >
            <el-option
              v-for="(batchitem, batchindex) in varietylist"
              :key="batchindex"
              :label="batchitem"
              :value="batchitem"
            />
          </el-select>
        </div>
        <div v-if="systemPathStatus" class="common-search-item">
          <el-select
            v-model="facilityNo"
            placeholder="请选择设施"
            filterable
            clearable
            @change="productionBaselist($event, '设施')"
          >
            <el-option
              v-for="item in facilityArr"
              :key="item.facilityNo"
              :value="item.facilityNo"
              :label="item.facilityName"
            />
          </el-select>
        </div>
        <div v-if="systemPathStatus" class="common-search-item">
          <el-select
            v-model="batchNo"
            class="input-select"
            filterable
            clearable
            placeholder="请选择批次名称"
            @change="search()"
          >
            <el-option
              v-for="(batchitem, batchindex) in productionBaseList"
              :key="batchindex"
              :label="batchitem.batchName"
              :value="batchitem.batchNo"
            />
          </el-select>
        </div>

        <div class="common-search-item">
          <!-- <div class="topview-pici-title">溯源配置编号：</div> -->
          <el-select
            v-model="productTraceNos"
            placeholder="请选择溯源配置编号"
            filterable
            clearable
            @change="search()"
          >
            <el-option
              v-for="item in productTraceCodeList"
              :key="item.productTraceNo"
              :label="item.productTraceCode"
              :value="item.productTraceNo"
            />
          </el-select>
        </div>
      </SearchBox>
    </template>
    <template v-slot:dialog>
      <el-dialog
        width="30%"
        :title="titleText + '配置溯源信息'"
        :visible.sync="dialogFormVisible"
        :before-close="handleClose"
      >
        <div>
          <el-form
            ref="formData"
            :model="formData"
            :rules="rules"
            label-position="left"
            class="w100p"
          >
            <el-form-item label="溯源信息来源:" prop="type" class="w100p">
              <el-select
                v-model="formData.type"
                clearable
                filterable
                placeholder="请选择溯源信息来源"
                :disabled="!titleInput"
                @change="typeChange"
              >
                <el-option
                  v-for="(item, index) in systemPathList"
                  :key="index"
                  :label="item.name"
                  :value="item.type"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="选择溯源范围：" class="w100p">
              <el-checkbox-group
                v-model="scopeData"
                :disabled="!canInput"
                @change="scopeDataInfo"
              >
                <el-checkbox-button
                  v-for="(city, index) in scopeList"
                  :key="index"
                  :label="city.type"
                  :disabled="city.type === 'MACHINING' ? true : false"
                >{{ city.name }}</el-checkbox-button>
              </el-checkbox-group>
            </el-form-item>
            <p v-if="!machiningTraceStatus || !productionTraceStatus">批次信息：</p>
            <el-form-item
              v-if="!machiningTraceStatus || !productionTraceStatus"
              label="批次名称 :"
              class="w100p"
            >
              <el-form-item v-if="!machiningTraceStatus" class="w50p">
                <el-select
                  v-model="machiningTraceSourceId"
                  :disabled="!canInput"
                  clearable
                  filterable
                  placeholder="请选择加工批次"
                  @change="machiningSearch($event, 'PRODUCTION')"
                >
                  <el-option
                    v-for="(productitem, productindex) in machiningList"
                    :key="productindex"
                    :label="productitem.batchName"
                    :value="productitem"
                  />
                </el-select>
              </el-form-item>
              <el-form-item v-if="!productionTraceStatus" class="w50p">
                <el-select
                  v-model="productionTraceSourceId"
                  clearable
                  :disabled="!canInput"
                  filterable
                  placeholder="请选择生产批次"
                  @change="productionSearch($event, '')"
                >
                  <el-option
                    v-for="(productitem, productindex) in producList"
                    :key="productindex"
                    :label="productitem.batchName"
                    :value="productindex"
                  />
                </el-select>
              </el-form-item>
            </el-form-item>
            <p v-if="!productionTraceStatus">生产溯源可见信息：</p>
            <el-form-item v-if="!productionTraceStatus" class="w100p checkbox">
              <el-checkbox
                v-if="!artificialProductionStatus"
                v-model="productionTraceConfig.pest"
                :disabled="!canInput"
              >{{ farmingTypeTitles }}记录</el-checkbox>
              <el-checkbox
                v-model="productionTraceConfig.inputs"
                :disabled="!canInput"
              >农资投入</el-checkbox>
              <el-checkbox
                v-if="!artificialProductionStatus"
                v-model="productionTraceConfig.growthPicture"
                :disabled="!canInput"
              >生长记录图片</el-checkbox>
              <el-checkbox
                v-if="!artificialProductionStatus"
                v-model="productionTraceConfig.growthData"
                :disabled="!canInput"
              >生长数据</el-checkbox>
              <el-checkbox
                v-model="productionTraceConfig.operation"
                :disabled="!canInput"
              >农事作业数据</el-checkbox>
            </el-form-item>
            <p v-if="!machiningTraceStatus">加工溯源可见信息：</p>
            <el-form-item v-if="!machiningTraceStatus" class="w100p checkbox">
              <el-checkbox
                v-model="machiningTraceConfig.equipment"
                :disabled="!canInput"
              >加工设备信息</el-checkbox>
              <el-checkbox
                v-model="machiningTraceConfig.material"
                :disabled="!canInput"
              >加工物料信息</el-checkbox>
              <el-checkbox
                v-model="machiningTraceConfig.personnel"
                :disabled="!canInput"
              >加工人员信息</el-checkbox>
            </el-form-item>
          </el-form>
        </div>
        <span v-if="canInput" slot="footer" class="dialog-footer">
          <el-button class="zh-button-one" @click="reset('formData')">取 消</el-button>
          <el-button
            class="zh-button-two"
            type="primary"
            @click="save('formData')"
          >确 定</el-button>
        </span>
      </el-dialog>
      <!-- 生成溯源码 -->
      <div class="codeview">
        <el-dialog width="40%" title="查看溯源码" :visible.sync="isshowcodeview">
          <div class="codeview-box">
            <p>生成溯源码数量：</p>
            <!-- <el-input v-model="GenerateCode" clearable /> -->
            <el-input-number
              v-model="GenerateCode"
              controls-position="right"
              :min="1"
              :max="999"
            />
          </div>
          <span slot="footer">
            <el-button class="zh-button-one" @click="isshowcodeview = false">取 消</el-button>
            <el-button
              class="zh-button-two"
              type="primary"
              @click="traceNoT('formData')"
            >生成溯源码</el-button>
          </span>
        </el-dialog>
      </div>
      <el-dialog width="40%" title="预览溯源码" :visible.sync="traceCodeExcelStatus">
        <el-table
          ref="traceCodeIData"
          v-loading="loading"
          highlight-current-row
          :data="traceCodeIData"
          stripe
          border
          height="100%"
          @selection-change="handleIExcelChange"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column type="index" label="序号" width="60" />
          <el-table-column prop="traceNo" label="溯源码" />
          <el-table-column prop="productTraceConfig.configTime" label="生成时间" />
          <el-table-column prop="average" label="预览">
            <template slot-scope="scope">
              <el-button
                type="primary"
                @click.stop="configIcon(scope.row.traceNo)"
              >预览溯源码</el-button>
            </template>
          </el-table-column>
        </el-table>
        <span slot="footer" class="dialog-footer">
          <el-button
            class="zh-button-one"
            @click="traceCodeExcelStatus = false"
          >取 消</el-button>
          <el-button
            class="zh-button-two"
            type="primary"
            @click="
              traceSelect({
                organizationNo: organizationNo,
                productTraceNo: productTraceNo
              })
            "
          >导出全部</el-button>
          <el-button type="primary" @click="traceCodeIExcel(organizationNo)">导出</el-button>
          <el-button v-if="judgePermission(87, 'print')" type="warning"
            @click="btnClickPrint2">打印设计</el-button>
          <el-button type="primary" @click="btnClickPrint">打印</el-button>
        </span>
      </el-dialog>
      <div class="codeview">
        <el-dialog width="40%" title="预览溯源码" :visible.sync="traceCodeStatus">
          <vue-qr
            :text="downloadData.url"
            :margin="10"
            color-dark="#000"
            color-light="#fff"
            :dot-scale="1"
            :logo-scale="0.2"
            :size="200"
            :logo-src="downloadData.icon"
          />
        </el-dialog>
      </div>
    </template>

    <template v-slot:table-box>
      <el-table
        ref="tableData"
        v-loading="loading"
        class="tableData"
        highlight-current-row
        :data="tableData"
        stripe
        border
        height="88%"
        @row-click="handleEdit"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" :selectable="selectable" width="55" />
        <el-table-column type="index" label="序号" width="60" />
        <el-table-column prop="productTraceNo" label="溯源配置编号" min-width="180" />
        <el-table-column
          v-if="systemPathStatus"
          prop="productionTraceConfig.batchNo"
          label="批次编号"
          min-width="200"
        />
        <el-table-column
          v-if="systemPathStatus"
          prop="productionTraceConfig.batchName"
          label="批次名称"
          min-width="200"
        />
        <el-table-column prop="type" label="溯源信息来源">
          <template slot-scope="scope">
            <span v-if="scope.row.type === '手动'">手动录入</span>
            <span v-if="scope.row.type === '自动'">系统生成</span>
          </template>
        </el-table-column>

        <el-table-column prop="Code" label="溯源范围" min-width="100">
          <template slot-scope="scope">
            <span v-if="scope.row.machiningExist">加工管理</span>
            <br v-if="scope.row.machiningExist && scope.row.productionExist" />
            <span v-if="scope.row.productionExist">生产管理</span>
          </template>
        </el-table-column>
        <el-table-column prop="configTime" label="配置时间" min-width="100" />
        <el-table-column label="操作" width="300">
          <template v-if="scope.row.productTraceNo" slot-scope="scope">
            <el-button
              type="warning"
              class="traceCodeIcon"
              size="mini"
              plain
              @click.stop="showcodeview(scope.row.productTraceNo)"
            >查看详细配置</el-button>
            <el-button
              type="info"
              class="traceCodeIcon"
              size="mini"
              plain
              @click.stop="
                traceNo(
                  scope.row.productTraceNo,
                  scope.row.organizationNo
                )
              "
            >生成溯源码</el-button>
            <br />
            <el-button
              type="success"
              class="traceCodeIcon"
              size="mini"
              plain
              @click.stop="traceCodeI(scope.row)"
            >查看溯源码</el-button>
            <el-button
              type="danger"
              class="traceCodeIcon"
              size="mini"
              plain
              @click.stop="traceSelect(scope.row)"
            >导出全部溯源码</el-button>
          </template>
        </el-table-column>
      </el-table>
      <Pagination
        :page-size="pagmes.pageSize"
        :current-page="pagmes.currentPage"
        :total-size="pagmes.totalSize"
        @changePageSize="changePageSize"
        @changeCurrentPage="changeCurrentPage"
      />
    </template>
  </baseMainSlot>
</template>
<script>
import { mapGetters } from "vuex";
import baseMainSlot from "@/components/BaseMainSlot/newBaseMainSlot.vue";
import sourceApi from "@/api/trace-source-web/tracing-source-code/tracing-source-code";
import Pagination from "@/components/Pagination";
import ActionBar from "@/components/ActionBar";
import selectbutton from "@/components/selectbutton/index.vue";
// import axios from "axios";
import divideInfoManage from "@/api/trace-source-web/land-manage/divide-manage";
import { getToken } from "@/utils/auth";
import { mymixin } from "@/utils/mixin";
import graApi from "@/api/trace-source-web/production-api/index-primary.js";
import vueQr from "vue-qr";
import batchreq from "@/api/trace-source-web/common-production/index";
import SearchBox from "@/components/SearchBox";
import { getLodop } from '@/plugins/LodopFuncs';

import { farmingTypeTitle } from "@/utils/validate";
export default {
  // eslint-disable-next-line vue/name-property-casing
  name: "configurationTracingSourceCode",
  components: {
    baseMainSlot,
    Pagination,
    selectbutton,
    ActionBar,
    SearchBox,
    vueQr
  },
  mixins: [mymixin],
  data() {
    return {
      loading: false,
      // 输入框是否可修改true为可修改
      canInput: false,
      titleInput: false,
      // 添加删除修改状态---主要通过此状态来判断调用方法
      nowChanceStau: "",
      farmingTypeTitles: farmingTypeTitle(),
      // 操作按钮的逻辑及展示数据
      addActive: true,
      delActive: false,
      saveActive: false,
      cancelActive: false,
      editActive: false,
      dialogFormVisible: false,
      isshowcodeview: false,
      tableData: [],
      formData: {
        organizationNo: sessionStorage.organizationNo,
        type: "", // 手动，还是自动
        scopeStart: "", // 开始阶段
        scopeEnd: "" // 结束阶段
      },
      image: null,
      imgurl: "",
      scopeData: [],
      traceCodeIData: [],
      scopeList: [
        {
          type: "MACHINING",
          name: "加工管理"
        },
        {
          type: "PRODUCTION",
          name: "生产管理"
        }
      ],
      machiningTraceStatus: true,
      productionTraceStatus: true,
      machiningList: [],
      machiningProduction: [],
      scopeSearch: [],
      machiningTraceSourceId: "",
      productionTraceSourceId: "",
      productTraceNos: undefined,
      producList: [],
      machiningTraceConfig: {
        equipment: false,
        material: false,
        personnel: false,
        traceSourceNo: ""
      },
      productionTraceConfig: {
        growthPicture: false,
        growthData: false,
        operation: false,
        inputs: false,
        pest: false,
        traceSourceNo: ""
      },
      productTraceConfigIdList: [],
      buttonselectlist: [],
      productionList: [],
      artificialProductionList: [],
      GenerateCode: 1,
      productTraceNo: undefined,
      // 搜索信息
      productTraceCodeList: [],
      traceCodeExcelStatus: false,
      traceCodeStatus: false,
      downloadData: {
        url: "",
        icon: ""
      },
      topitemtypeid: 0,
      isshowview: false,
      nowimageurl: "",
      pagmes: {
        pageSize: 10,
        currentPage: 1,
        totalSize: 0
      },
      rules: {
        type: [
          { required: true, message: "请选择溯源信息来源", trigger: "change" }
        ]
      },
      artificialProductionStatus: false,
      scopeType: "",
      SRCImage: "",
      traceNoIdList: [],
      varietylist: [],
      varietyName: undefined,
      facilityArr: [],
      productionBaseList: [],
      facilityNo: "",
      type: "",
      batchNo: undefined,
      // 系统路径
      systemPathList: [
        { type: "自动", name: "系统生成" },
        { type: "手动", name: "手动录入" }
      ],
      systemPathStatus: false
    };
  },
  created() {
    this.getbatchselect();
    this.traceCode();
    this.getFacilityListByConditionAll();
  },
  computed: {
    ...mapGetters({
      judgePermission: "permission/judgePermission"
    })
  },
  mounted() {
    // this.getbatchselect()
    // console.log(this.hasRoute('ManualTraceabilityInformationManagement'))
  },
  methods: {
    // hasRoute(name, routeList) {
    //   !routeList && (routeList = this.$router.options.routes, console.log('执行'))
    //   for (let i = 0; i < routeList.length; i++) {
    //     console.log(routeList[i])
    //     if (routeList[i].name === name) {
    //       return true
    //     }
    //     if (routeList[i].children) {
    //       let flag = this.hasRoute(name, routeList[i].children)
    //       if (flag) {
    //         return flag
    //       }
    //     }
    //   }
    //   return false
    // },
    // 按钮当前选择index
    nowselectbuttonindex(i) {
      this.topitemtypeid = i;
      this.getTableDataList();
    },
    selectable(row, index) {
      return row.status === false; // 通过某个值来进行判断，规定那一行的选择框被禁用
    },
    traceCode() {
      graApi.traceCodeImage(getToken("organizationNo")).then(res => {
        // console.log(res.data)
        let data = res.data;
        this.SRCImage = "data:image/png;base64," + data[0]?.imageData || "";
      });
    },
    // 获取批次下拉数据
    getbatchselect() {
      this.productionBaselist();
      this.artificialProduclist();
      this.machiningBaselist();
      this.productTraceCondition();
      this.queryriebylist();
      this.getFacilityListByConditionAll();
    },
    systemPathInfo(e = null) {
      if (e === "自动") {
        this.systemPathStatus = true;
        // setTimeout(() => {
        this.productTraceCondition(e);
        this.productTraceNo = undefined;
        this.varietyName = undefined;
        this.facilityNo = undefined;
        this.batchNo = undefined;
        this.getTableDataList();
        this.$refs.tableData.style = {
          height: "100%"
        };
        // }, 100)
      }
      if (e === "手动") {
        this.systemPathStatus = false;
        this.productTraceCondition(e);
        this.productTraceNo = undefined;
        this.varietyName = undefined;
        this.facilityNo = undefined;
        this.batchNo = undefined;
        this.getTableDataList();
      }
      if (!e) {
        this.systemPathStatus = false;
        this.productTraceNo = undefined;
        this.varietyName = undefined;
        this.facilityNo = undefined;
        this.batchNo = undefined;
        this.productTraceCondition();
        this.getTableDataList();
      }
    },
    // 生产批次
    async productionBaselist(e = null, x = null) {
      // console.log(e, x)
      let params = {
        farmingTypeNo: sessionStorage.farmingTypeNo
      };
      if (x === "品种") {
        params["varietyName"] = e;
      }
      if (x === "设施") {
        params["facilityNo"] = e;
      }
      const { data: resp } = await sourceApi.productionBaselist(params);
      if (!e) {
        this.productionList = resp;
        this.producList = [...this.productionList];
        this.productionBaseList = [...resp];
      }
      if (e) {
        this.productionBaseList = resp;
        this.getTableDataList();
      }
    },
    // 生产批次手动
    async artificialProduclist() {
      const { data: resp } = await sourceApi.artificialProductionlist(
        sessionStorage.farmingTypeNo,
        {
          farmingTypeNo: sessionStorage.farmingTypeNo
        }
      );
      this.artificialProductionList = resp;
    },
    // 加工批次
    async machiningBaselist() {
      const { data: resp } = await sourceApi.machiningBaselist(
        sessionStorage.farmingTypeNo,
        {
          farmingTypeNo: sessionStorage.farmingTypeNo
        }
      );
      this.machiningList = resp;
    },
    // 所有
    async productTraceCondition(e) {
      const { data: resp } = await sourceApi.productTraceCondition({
        farmingTypeNo: sessionStorage.farmingTypeNo,
        type: e
      });
      this.productTraceCodeList = resp;
    },
    // 种养品种
    async queryriebylist() {
      const { data: resp } = await batchreq.queryriebylist(
        sessionStorage.farmingTypeNo,
        {
          farmingTypeNo: sessionStorage.farmingTypeNo
        }
      );
      this.varietylist = resp;
    },
    // 所有地块
    async getFacilityListByConditionAll(e = null) {
      let params = {
        // facilityStatus: 1
        // plantingTypeName: '小麦'
      };
      const {
        data: resp
      } = await divideInfoManage.getFacilityListByConditionAll(params);
      this.facilityArr = resp;
      if (e) {
        this.getTableDataList();
      }
    },
    //   获取表格信息
    getTableDataList() {
      let start = true;
      let end = false;
      let params = {
        page: this.pagmes.currentPage,
        size: this.pagmes.pageSize,
        entity: {}
      };
      // 判断阶段
      if (this.scopeSearch.length > 0) {
        if (this.scopeSearch[0] === this.scopeSearch.slice(-1)[0]) {
          if (this.scopeSearch[0] === "MACHINING") {
            start = false;
            end = true;
          } else if (this.scopeSearch[0] === "PRODUCTION") {
            start = true;
            end = false;
          }
        }
        if (this.scopeSearch[0] !== this.scopeSearch.slice(-1)[0]) {
          start = true;
          end = true;
        }
      }
      // 自动传输条件
      if (this.type === "自动") {
        params["entity"] = {
          productTraceNo: this.productTraceNo || undefined,
          type: this.type || undefined,
          productionExist: start || undefined,
          machiningExist: end || undefined,
          productionTraceConfig: {
            varietyName: this.varietyName || undefined,
            facilityNo: this.facilityNo || undefined,
            batchNo: this.batchNo || undefined
          }
        };
      } else {
        // 手动传输条件
        params["entity"] = {
          productTraceNo: this.productTraceNos || undefined,
          type: this.type || undefined,
          productionExist: start || undefined,
          machiningExist: end || undefined
        };
      }
      sourceApi.productTracePageList(params).then(res => {
        if (res.code === 1) {
          let data = res.data;
          this.pagmes.totalSize = data.totalElements;

          let content = data.content;
          content.forEach(item => {
            if (item.scopeEnd === item.scopeStart) {
              if (item.scopeEnd === "MACHINING") {
                this.$set(item, "Code", "加工管理");
              }
              if (item.scopeEnd === "PRODUCTION") {
                this.$set(item, "Code", "生产管理");
              }
            } else {
              let start = "";
              let end = "";
              if (item.scopeStart === "MACHINING") start = "加工管理";
              if (item.scopeEnd === "PRODUCTION") end = "生产管理";
              this.$set(item, "Code", start + "-" + end);
            }
          });
          this.tableData = content;
        } else {
          this.tableData = [];
        }
        this.addblankmet();
      });
    },
    //
    scopeDataInfo(val) {
      // 判断有没有选择两个以上的范围
      // this.machiningProduction = val;
      if (!this.formData.type) {
        return this.$message.warning("请先选择信息来源！！！");
      }
      if (val.length >= 2) {
        val.forEach(item => {
          if (item === "MACHINING") {
            this.$set(this.formData, "scopeStart", item);
            this.$set(this.formData, "machiningExist", true);
            this.machiningTraceStatus = false;
          }
          if (item === "PRODUCTION") {
            this.$set(this.formData, "scopeEnd", item);
            this.$set(this.formData, "productionExist", true);
            this.productionTraceStatus = false;
          }
        });
        this.productionTraceSourceId = "";
        this.producList = [];
      }
      // 判断是生产还是加工
      if (val.length === 1) {
        if (val[0] === "MACHINING") {
          this.$set(this.formData, "scopeStart", val[0]);
          this.$set(this.formData, "machiningExist", true);
          this.$set(this.formData, "productionExist", false);
          this.$set(this.formData, "scopeEnd", val[0]);
          this.machiningTraceStatus = false;
        } else {
          this.machiningTraceStatus = true;
        }
        if (val[0] === "PRODUCTION") {
          if (this.formData.type === "手动") {
            this.producList = [...this.artificialProductionList];
            // console.log(this.producList, 1)
          } else if (this.formData.type === "自动") {
            this.producList = [...this.productionList];
            // console.log(this.producList, 2)
          }
          this.productionTraceStatus = false;
          this.$set(this.formData, "productionExist", true);
          this.$set(this.formData, "machiningExist", false);
          this.$set(this.formData, "scopeStart", val[0]);
          this.$set(this.formData, "scopeEnd", val[0]);
        } else {
          this.productionTraceStatus = true;
        }
      }
      if (val.length === 0) {
        this.machiningTraceStatus = true;
        this.productionTraceStatus = true;
        this.$set(this.formData, "productionExist", false);
        this.$set(this.formData, "machiningExist", false);
        this.$set(this.formData, "scopeStart", "");
        this.$set(this.formData, "scopeEnd", "");
      }
    },
    // 选择加工查询生产
    machiningSearch(e, type) {
      if (e) {
        this.$set(this.machiningTraceConfig, "traceSourceNo", e.traceSourceNo);
        this.$set(
          this.formData,
          "machiningTraceConfigId",
          e.machiningBaseInfoId
        );
        if (this.scopeData.length > 1) {
          if (this.machiningTraceStatus === false) {
            this.productionTraceSourceId = "";
            sourceApi
              .traceMapperlist({ traceSourceNo: e, batchType: type })
              .then(res => {
                this.producList = res.data;
              });
          }
        }
      } else {
        this.$set(this.machiningTraceConfig, "traceSourceNo", "");
      }
    },
    productionSearch(e, type) {
      let x = this.producList[e];
      if (x) {
        // console.log(e)
        if (this.formData.type === "手动") {
          this.$set(
            this.productionTraceConfig,
            "traceSourceNo",
            x.artificialProductionBaseInfoNo
          );
          this.$set(
            this.formData,
            "artificialProductionBaseInfoNo",
            x.artificialProductionBaseInfoNo
          );
          // return e.artificialProductionBaseInfoNo
          // 'productionTraceSourceId' =  e.artificialProductionBaseInfoNo
          // this.producList = [...this.artificialProductionList];
          // console.log(this.producList, 1)
        } else if (this.formData.type === "自动") {
          this.$set(
            this.productionTraceConfig,
            "traceSourceNo",
            x.traceSourceNo
          );
          this.$set(
            this.formData,
            "productionBaseInfoId",
            x.productionBaseInfoId
          );
          // this.productionTraceSourceId =  e.productionBaseInfoId
        }
        // return e.artificialProductionBaseInfoNo
        if (this.scopeData.length === 1) {
          if (this.productionTraceStatus === false) {
            if (this.formData.type === "手动") {
              this.producList = [...this.artificialProductionList];
              // console.log(this.producList, 1)
            } else if (this.formData.type === "自动") {
              this.producList = [...this.productionList];
            }
          }
        }
      } else {
        this.$set(this.productionTraceConfig, "traceSourceNo", "");
      }
    },
    typeChange(e) {
      this.machiningTraceConfig = {
        equipment: false,
        material: false,
        personnel: false,
        traceSourceNo: ""
      };
      this.productionTraceConfig = {
        growthPicture: false,
        growthData: false,
        operation: false,
        inputs: false,
        pest: false,
        traceSourceNo: ""
      };
      this.scopeData = [];
      this.machiningTraceSourceId = "";
      this.productionTraceSourceId = "";
      this.machiningTraceStatus = true;
      this.productionTraceStatus = true;
      this.artificialProductionStatus = false;
      if (e === "自动") {
        this.producList = [...this.productionList];
      }
      if (e === "手动") {
        this.producList = [...this.artificialProductionList];
        this.artificialProductionStatus = true;
      }
    },
    traceNo(e, s) {
      this.productTraceNo = e;
      this.organizationNo = s;
      this.isshowcodeview = true;
    },
    // 生产溯源码
    traceNoT() {
      this.isshowcodeview = true;
      if (this.GenerateCode < 1) {
        this.$message.warning("数量不能少于1");
        return;
      }
      if (this.GenerateCode > 999) {
        this.$message.warning("数量不能少于1");
        this.GenerateCode = 999;
        return;
      }
      let params = {
        organizationNo: sessionStorage.organizationNo,
        productTraceNo: this.productTraceNo,
        frequency: this.GenerateCode
      };
      sourceApi.traceNoList(params).then(res => {
        // console.log()
        if (res.code === 1) {
          // this.$message.success('添加成功')
          sourceApi
            .editTraceCode({
              productTraceNo: this.productTraceNo,
              status: true
            })
            .then(res => {
              if (res.code === 1) {
                this.$message.success("添加成功");
                this.$confirm("是否直接导出溯源码？", "确认信息", {
                  distinguishCancelAndClose: true,
                  confirmButtonText: "导出",
                  cancelButtonText: "取消"
                })
                  .then(() => {
                    this.isshowcodeview = false;
                    this.traceSelect({
                      organizationNo: this.organizationNo,
                      productTraceNo: this.productTraceNo
                    });
                    this.productTraceNo = "";
                  })
                  .catch(action => {
                    this.$message({
                      type: "info",
                      message:
                        action === "cancel"
                          ? "放弃保存并离开页面"
                          : "停留在当前页面"
                    });
                    this.productTraceNo = "";
                  });
                this.isshowcodeview = false;
                this.GenerateCode = 1;
                this.getTableDataList();
              } else {
                this.$message.warning("添加失败");
              }
            });
        } else {
          this.$message.warning("添加失败");
        }
      });
      // <el-button @click="traceSelect({ organizationNo: organizationNo, productTraceNo: productTraceNo })">取 消</el-button>
    },
    traceCodeI(e) {
      this.traceCodeExcelStatus = true;
      this.productTraceNo = e.productTraceNo;
      this.organizationNo = e.organizationNo;
      sourceApi
        .traceByCondition({ productTraceNo: e.productTraceNo })
        .then(res => {
          const data = res.data;
          this.traceCodeIData = data;
        });
    },
    configIcon(e) {
      this.$set(
        this.downloadData,
        "url",
        `${this.$webSerUrl}mateFarmTraceSource/#/pages/loading-trace/loading-trace?traceNo=${e}&databaseName=${sessionStorage.databaseName}`
      );
      this.$set(this.downloadData, "icon", this.SRCImage || "");
      this.traceCodeStatus = true;
    },
    // 导出全部溯源码
    traceSelect(e) {
      sourceApi
        .traceExcelAll({
          productTraceNo: e.productTraceNo,
          organizationNo: e.organizationNo
        })
        .then(res => {
          const data = res;
          // let traceNoIdList = batchList.map(item => item.traceNoId)
          // sourceApi.traceExcel(traceNoIdList).then(res => {
          //   let data = res
          //   // this.dialogFormVisible = false
          // const blob = new Blob([data], {
          //   type: "application/vnd.ms-download;charset=utf-8"
          // });
          const blob = new Blob([data], {
            type: "application/vnd.ms-excel;charset=utf-8"
          });
          const link = document.createElement("a");
          // link.download = `溯源码-${this.dateToFormat(new Date())}.doc`;
          link.download = `溯源码-${this.dateToFormat(new Date())}.xls`;
          // console.log(data)
          link.style.display = "none";
          // console.log(blob)
          link.href = URL.createObjectURL(blob);
          document.body.appendChild(link);
          link.click();
          URL.revokeObjectURL(link.href);
          document.body.removeChild(link);
          // });
        });
    },
    traceCodeIExcel(e) {
      if (this.traceNoIdList.length <= 0) {
        return this.$message.warning("请至少选择一个溯源码");
      }
      sourceApi.traceExcel(this.traceNoIdList, e).then(res => {
        let data = res;
        // const blob = new Blob([data], {
        //   type: "application/vnd.ms-download;charset=utf-8"
        // });
        const blob = new Blob([data], {
          type: "application/vnd.ms-excel;charset=utf-8"
        });
        const link = document.createElement("a");
        // link.download = `溯源码-${this.dateToFormat(new Date())}.doc`;
        link.download = `溯源码-${this.dateToFormat(new Date())}.xls`;
        // console.log(data)
        link.style.display = "none";
        // console.log(blob)
        link.href = URL.createObjectURL(blob);
        document.body.appendChild(link);
        link.click();
        URL.revokeObjectURL(link.href);
        document.body.removeChild(link);
        this.traceCodeExcelStatus = false;
      });
    },
    handleIExcelChange(list) {
      this.traceNoIdList = [];
      this.traceNoIdList = list.map(item => item.traceNo);
      // if (this.traceNoIdList.length > 0) this.delActive = true;
      // else this.delActive = false;
    },
    search() {
      this.currentPage = 1;
      this.getTableDataList();
    },
    changePageSize(pageSize) {
      this.pagmes.pageSize = pageSize;
      this.getTableDataList();
    },
    changeCurrentPage(currentPage) {
      this.pagmes.currentPage = currentPage;
      this.getTableDataList();
    },
    // 点击行
    handleEdit(row) {
      // console.log(row);
      // TODO 点击行元素后 edit
      this.addHide = true;
      this.addActive = true;
      this.editActive = true;
      this.saveActive = false;
      this.canInput = false;
      if (row.type === "自动") {
        this.artificialProductionStatus = false;
        sourceApi.productTraceQuery(row.productTraceNo).then(res => {
          // console.log(res.data)
          let data = res.data;
          this.formData = { ...data };

          if (this.formData.productionExist && this.formData.machiningExist) {
            if (this.formData.scopeStart === "MACHINING") {
              this.$set(this.scopeData, 0, "MACHINING");
            }
            if (this.formData.scopeEnd === "PRODUCTION") {
              this.$set(this.scopeData, 1, "PRODUCTION");
            }
          } else {
            if (this.formData.machiningExist) {
              this.$set(this.scopeData, 0, "MACHINING");
            }
            if (this.formData.productionExist) {
              this.$set(this.scopeData, 0, "PRODUCTION");
            }
          }
          if (
            this.formData.machiningTraceConfig !== undefined &&
            this.formData.productionTraceConfig !== undefined
          ) {
            this.machiningTraceConfig = this.formData.machiningTraceConfig;
            this.productionTraceConfig = this.formData.productionTraceConfig;
            this.machiningTraceStatus = false;
            this.productionTraceStatus = false;
            this.machiningSearch(
              this.formData.productionTraceConfig.traceSourceNo,
              "PRODUCTION"
            );
            this.machiningTraceSourceId = {
              machiningTraceSourceId: this.formData.machiningTraceConfig
                .traceSourceNo
            };
            // this.productionTraceSourceId = {
            //   batchNo: this.formData.productionTraceConfig
            //     .batchNo
            // };
            this.producList.forEach((item, index) => {
              if (
                item.batchNo === this.formData.productionTraceConfig.batchNo
              ) {
                this.productionTraceSourceId = index;
              }
            });
          } else if (this.formData.machiningTraceConfig !== undefined) {
            this.machiningTraceConfig = this.formData.machiningTraceConfig;
            this.machiningTraceSourceId = {
              machiningTraceSourceId: this.formData.machiningTraceConfig
                .traceSourceNo
            };
            this.productionTraceStatus = true;
            this.machiningTraceStatus = false;
          } else if (this.formData.productionTraceConfig !== undefined) {
            this.productionTraceConfig = this.formData.productionTraceConfig;
            // this.productionTraceSourceId = {
            //   batchNo: this.formData.productionTraceConfig
            //     .batchNo
            // };
            this.producList.forEach((item, index) => {
              if (
                item.batchNo === this.formData.productionTraceConfig.batchNo
              ) {
                this.productionTraceSourceId = index;
              }
            });
            this.machiningTraceStatus = true;
            this.productionTraceStatus = false;
            this.producList = [...this.productionList];
          }
        });
      }
      if (row.type === "手动") {
        this.artificialProductionStatus = true;
        sourceApi.productTraceQuery(row.productTraceNo).then(res => {
          let data = res.data;
          this.formData = { ...data };
          if (this.formData.productionExist && this.formData.machiningExist) {
            if (this.formData.scopeStart === "MACHINING") {
              this.$set(this.scopeData, 0, "MACHINING");
            }
            if (this.formData.scopeEnd === "PRODUCTION") {
              this.$set(this.scopeData, 1, "PRODUCTION");
            }
          } else {
            if (this.formData.machiningExist) {
              this.$set(this.scopeData, 0, "MACHINING");
            }
            if (this.formData.productionExist) {
              this.$set(this.scopeData, 0, "PRODUCTION");
            }
          }
          if (this.formData.artificialProductionTraceConfig !== undefined) {
            this.productionTraceStatus = false;
            this.productionTraceConfig = this.formData.artificialProductionTraceConfig;
            // this.productionTraceSourceId = {
            //   productionTraceSourceId: this.formData
            //     .artificialProductionTraceConfig.artificialProductionBaseInfoNo
            // };
            this.producList = [...this.artificialProductionList];

            this.producList.forEach((item, index) => {
              if (this.formData.artificialProductionTraceConfig) {
                if (
                  item.artificialProductionBaseInfoNo ===
                  this.formData.artificialProductionTraceConfig
                    .artificialProductionBaseInfoNo
                ) {
                  this.productionTraceSourceId = index;
                }
              }
            });
            // this.producList = [...this.artificialProductionList];
          }
        });
      }
      // console.log(this.scopeData)
      if (row.status === true) {
        this.editActive = false;
      }
    },
    handleSelectionChange(list) {
      this.productTraceConfigIdList = [];
      this.productTraceConfigIdList = list.map(item => item.productTraceNo);
      if (this.productTraceConfigIdList.length > 0) this.delActive = true;
      else this.delActive = false;
    },
    delmessage() {
      sourceApi
        .delTraceCode({
          productTraceNoList: this.productTraceConfigIdList
        })
        .then(res => {
          if (res.code === 1) {
            this.$message.success(res.msg);
            this.getTableDataList();
            this.resetActionBar();
          } else {
            this.$message.warning(res.msg || "删除失败");
          }
        });
    },
    // 设置图片
    setimage(e) {
      this.nowimageurl = e;
    },
    // 展示当前编码
    showcodeview(e) {
      sourceApi.productTraceQuery(e).then(res => {
        // console.log(res.data)
        let data = res.data;
        this.formData = { ...data };
        if (data.type === "自动") {
          // console.log(res.data)
          let data = res.data;
          this.formData = { ...data };
          this.artificialProductionStatus = false;
          if (this.formData.productionExist && this.formData.machiningExist) {
            if (this.formData.scopeStart === "MACHINING") {
              this.$set(this.scopeData, 0, "MACHINING");
            }
            if (this.formData.scopeEnd === "PRODUCTION") {
              this.$set(this.scopeData, 1, "PRODUCTION");
            }
          } else {
            if (this.formData.machiningExist) {
              this.$set(this.scopeData, 0, "MACHINING");
            }
            if (this.formData.productionExist) {
              this.$set(this.scopeData, 0, "PRODUCTION");
            }
          }
          if (
            this.formData.machiningTraceConfig !== undefined &&
            this.formData.productionTraceConfig !== undefined
          ) {
            this.machiningTraceConfig = this.formData.machiningTraceConfig;
            this.productionTraceConfig = this.formData.productionTraceConfig;
            this.machiningTraceStatus = false;
            this.productionTraceStatus = false;
            this.machiningSearch(
              this.formData.productionTraceConfig.traceSourceNo,
              "PRODUCTION"
            );
            this.machiningTraceSourceId = {
              machiningTraceSourceId: this.formData.machiningTraceConfig
                .traceSourceNo
            };
            // this.productionTraceSourceId = {
            //   productionTraceSourceId: this.formData.productionTraceConfig
            //     .traceSourceNo
            // };
            this.producList.forEach((item, index) => {
              if (this.formData.productionTraceConfig) {
                if (
                  item.batchNo === this.formData.productionTraceConfig.batchNo
                ) {
                  this.productionTraceSourceId = index;
                }
              }
            });
          } else if (this.formData.machiningTraceConfig !== undefined) {
            this.machiningTraceConfig = this.formData.machiningTraceConfig;
            this.machiningTraceSourceId = {
              machiningTraceSourceId: this.formData.machiningTraceConfig
                .traceSourceNo
            };
            this.productionTraceStatus = true;
            this.machiningTraceStatus = false;
          } else if (this.formData.productionTraceConfig !== undefined) {
            this.productionTraceConfig = this.formData.productionTraceConfig;
            // this.productionTraceSourceId = {
            //   productionTraceSourceId: this.formData.productionTraceConfig
            //     .traceSourceNo
            // };
            this.producList.forEach((item, index) => {
              if (this.formData.productionTraceConfig) {
                if (
                  item.batchNo === this.formData.productionTraceConfig.batchNo
                ) {
                  this.productionTraceSourceId = index;
                }
              }
            });
            this.machiningTraceStatus = true;
            this.productionTraceStatus = false;
            this.producList = [...this.productionList];
          }
        } else if (data.type === "手动") {
          // console.log(res.data)
          let data = res.data;
          this.formData = { ...data };
          this.artificialProductionStatus = true;
          if (this.formData.productionExist && this.formData.machiningExist) {
            if (this.formData.scopeStart === "MACHINING") {
              this.$set(this.scopeData, 0, "MACHINING");
            }
            if (this.formData.scopeEnd === "PRODUCTION") {
              this.$set(this.scopeData, 1, "PRODUCTION");
            }
          } else {
            if (this.formData.machiningExist) {
              this.$set(this.scopeData, 0, "MACHINING");
            }
            if (this.formData.productionExist) {
              this.$set(this.scopeData, 0, "PRODUCTION");
            }
          }
          if (this.formData.artificialProductionTraceConfig !== undefined) {
            this.productionTraceStatus = false;
            this.productionTraceConfig = this.formData.artificialProductionTraceConfig;
            // this.productionTraceSourceId = {
            //   productionTraceSourceId: this.formData
            //     .artificialProductionTraceConfig.artificialProductionBaseInfoNo
            // };
            this.producList = [...this.artificialProductionList];

            this.producList.forEach((item, index) => {
              if (this.formData.artificialProductionTraceConfig) {
                if (
                  item.artificialProductionBaseInfoNo ===
                  this.formData.artificialProductionTraceConfig
                    .artificialProductionBaseInfoNo
                ) {
                  this.productionTraceSourceId = index;
                }
              }
            });
            // this.producList = [...this.artificialProductionList];
          }
        }

        this.titleText = "查看";
        this.canInput = false;
        this.titleInput = false;
        this.dialogFormVisible = true;
      });
    },
    // 展示添加弹框
    showaddig() {
      if (this.topitemtypeid === 0) {
        this.isshowview = true;
      } else {
        this.$message.warning("暂无加工数据！！");
      }
    },
    // 填充表格空白行
    addblankmet() {
      let havline = this.tableData.length % this.pagmes.pageSize;
      if (this.tableData.length < this.pagmes.pageSize) {
        if (havline < this.pagmes.pageSize) {
          const remain = this.pagmes.pageSize - havline;
          for (var i = 0; i < remain; i++) {
            this.tableData.push({ index: i + this.tableData.length - 1 });
          }
        }
      }
    },
    save(formData) {
      this.$refs[formData].validate(valid => {
        if (valid) {
          let params = {};
          if (this.nowChanceStau === "edit") {
            if (this.formData.type === "自动") {
              if (this.scopeData.length >= 2) {
                this.scopeData.forEach(item => {
                  if (item === "MACHINING") {
                    this.$set(
                      this.formData,
                      "machiningTraceConfig",
                      this.machiningTraceConfig
                    );
                  }
                  if (item === "PRODUCTION") {
                    this.$set(
                      this.formData,
                      "productionTraceConfig",
                      this.productionTraceConfig
                    );
                  }
                });
              }
              // 判断是生产还是加工
              if (this.scopeData.length === 1) {
                if (this.scopeData[0] === "MACHINING") {
                  this.$set(
                    this.formData,
                    "machiningTraceConfig",
                    this.machiningTraceConfig
                  );
                }
                if (this.scopeData[0] === "PRODUCTION") {
                  this.$set(
                    this.formData,
                    "productionTraceConfig",
                    this.productionTraceConfig
                  );
                }
              }
              if (this.scopeData.length === 0) {
                this.$message.warning("请至少选择一个溯源范围");
                return;
              }
              params = { ...this.formData };
            } else if (this.formData.type === "手动") {
              params = { ...this.formData };
              let inputs = this.productionTraceConfig.inputs;
              let artificialProductionBaseInfoNo = this.productionTraceConfig
                .traceSourceNo;
              let operation = this.productionTraceConfig.operation;
              let pars = {
                inputs: inputs,
                operation: operation,
                productTraceNo: this.formData.productTraceNo,
                artificialProductionBaseInfoNo: artificialProductionBaseInfoNo,
                artificialProductionTraceConfigId: this.formData
                  .artificialProductionTraceConfigId
              };
              params.artificialProductionTraceConfig = pars;
            }

            sourceApi.editTraceCode(params).then(res => {
              if (res.code === 1) {
                this.$message.success(res.msg || "修改成功！");
                this.$refs[formData].resetFields();
                this.getTableDataList();
                this.dialogFormVisible = false;
              } else {
                this.$message.error(res.msg || "修改失败！");
              }
            });
          } else if (this.nowChanceStau === "add") {
            let params = {};
            this.$set(
              this.formData,
              "organizationNo",
              sessionStorage.organizationNo
            );
            if (this.formData.type === "自动") {
              if (this.scopeData.length >= 2) {
                this.scopeData.forEach(item => {
                  if (item === "MACHINING") {
                    this.$set(
                      this.formData,
                      "machiningTraceConfig",
                      this.machiningTraceConfig
                    );
                  }
                  if (item === "PRODUCTION") {
                    this.$set(
                      this.formData,
                      "productionTraceConfig",
                      this.productionTraceConfig
                    );
                  }
                });
              }
              // 判断是生产还是加工
              if (this.scopeData.length === 1) {
                if (this.scopeData[0] === "MACHINING") {
                  this.$set(
                    this.formData,
                    "machiningTraceConfig",
                    this.machiningTraceConfig
                  );
                }
                if (this.scopeData[0] === "PRODUCTION") {
                  this.$set(
                    this.formData,
                    "productionTraceConfig",
                    this.productionTraceConfig
                  );
                }
              }
              if (this.scopeData.length === 0) {
                this.$message.warning("请至少选择一个溯源范围");
                return;
              }
              params = { ...this.formData };
            } else if (this.formData.type === "手动") {
              params = { ...this.formData };
              let inputs = this.productionTraceConfig.inputs;
              let artificialProductionBaseInfoNo = this.productionTraceConfig
                .traceSourceNo;
              let operation = this.productionTraceConfig.operation;
              let pars = {
                inputs: inputs,
                operation: operation,
                artificialProductionBaseInfoNo: artificialProductionBaseInfoNo
              };
              params.artificialProductionTraceConfig = pars;
            }
            console.log(params);
            // return;
            sourceApi.traceCode(params).then(res => {
              if (res.code === 1) {
                this.$message.success(res.msg || "新增成功！");
                this.$refs[formData].resetFields();
                this.reset();
                this.getTableDataList();
                this.dialogFormVisible = false;
              } else {
                // this.queryDatalist();
                this.$message.error(res.msg || "新增失败！");
              }
            });
          }
        } else {
          return false;
        }
      });
    },
    reset(formData) {
      this.formData = {
        organizationNo: sessionStorage.organizationNo,
        type: "", // 手动，还是自动
        scopeStart: "", // 开始阶段
        scopeEnd: "" // 结束阶段
      };
      this.machiningTraceConfig = {
        equipment: false,
        material: false,
        personnel: false,
        traceSourceNo: ""
      };
      this.productionTraceConfig = {
        growthPicture: false,
        growthData: false,
        operation: false,
        inputs: false,
        pest: false,
        traceSourceNo: ""
      };
      this.scopeData = [];
      this.machiningTraceSourceId = "";
      this.productionTraceSourceId = "";
      this.producList = [...this.productionList];
      this.machiningTraceStatus = true;
      this.productionTraceStatus = true;
      if (formData) {
        this.$refs[formData].resetFields();
      }
      this.addActive = true;
      this.dialogFormVisible = false;
    },
    // 打印
    btnClickPrint() {
      if (this.traceNoIdList.length <= 0) {
        return this.$message.warning("请至少选择一个溯源码");
      }
      
      let LODOP = getLodop()
      
      LODOP.SET_LICENSES("","897EEB36654654D6DCF80B006DB8E7C8","","");

      sourceApi.queryByOrganizationNo(sessionStorage.organizationNo).then(res => {
        let printScript = res.data?.tracePrintTemplate
        let count = (printScript ? printScript.split('${url}') : []).length - 1
        let len = this.traceNoIdList.length
        if (count) {
          // 遍历打印
          for (let i = 1; i <= len; i = i + count) {
            let printScript = res.data?.tracePrintTemplate
            let list = printScript.split('${url}') || [], str = ''
            for (let j = 0; j < count; j++) {
              if (i+j <= len) {
                let id = this.traceNoIdList[i + j - 1]
                let url = `${this.$webSerUrl}mateFarmTraceSource/#/pages/loading-trace/loading-trace?traceNo=${id}&databaseName=${sessionStorage.databaseName}`;
                str += list[j] + url
              }
            }
            str += list[list.length - 1]
            this.createTemp(str);
            LODOP.PRINT()
          }
        }
      })

    },
    // 打印设计
    btnClickPrint2() {
      let LODOP = getLodop()
      
      LODOP.SET_LICENSES("","897EEB36654654D6DCF80B006DB8E7C8","","");
      if (LODOP.CVERSION) {
        CLODOP.On_Return = (TaskID, Value) => {
          sourceApi.update({
            organizationNo: sessionStorage.organizationNo,
            tracePrintTemplate: Value
          }).then(res => {
            this.$message[res.code == 1 ? 'success' : 'error'](res.msg);
          })
        };
      }
      
      sourceApi.queryByOrganizationNo(sessionStorage.organizationNo).then(res => {
        let printScript = res.data.tracePrintTemplate
        this.createTemp(printScript);
        LODOP.PRINT_DESIGN()
      })
    },
    createTemp(printScript) {
      let LODOP = getLodop();
      
      LODOP.SET_LICENSES("","897EEB36654654D6DCF80B006DB8E7C8","","");
      eval(printScript);
    },
    // 添加
    add() {
      this.canInput = true;
      this.titleInput = true;
      this.nowChanceStau = "add";
      this.reset("");
      // this.productionBaselist()
      this.titleText = "添加";
      this.dialogFormVisible = true;
      this.addActive = false;
      this.delActive = false;
      this.saveActive = true;
      this.cancelActive = true;
      this.editActive = false;
    },
    // 修改
    edit() {
      this.nowChanceStau = "edit";
      this.titleText = "修改";
      this.dialogFormVisible = true;
      // this.productionBaselist()
      this.canInput = true;
      this.titleInput = false;
      this.addActive = false;
      this.delActive = false;
      this.saveActive = true;
      this.cancelActive = true;
      this.editActive = false;
    },
    handleClose(done) {
      this.resetActionBar();
      this.reset();
      done();
      // this.$confirm("确认关闭？")
      //   .then(_ => {
      //   })
      //   .catch(_ => {});
    }
  }
};
</script>
<style lang="scss" scoped>
::v-deep .el-form-item__label {
  color: #000 !important;
}
::v-deep .el-form-item__content {
  .el-input__inner {
    color: #000 !important;
  }
}
::v-deep.el-form-item--medium .el-form-item__content {
  display: flex;
}
::v-deep.el-select {
  width: 100%;
}
// .codeview {
//   ::v-deep.el-dialog {
//     height: 350px;
//   }
// }
// ::v-deep .el-dialog__footer {
//   position: absolute;
//   bottom: 20px;
//   right: 20px;
// }
.zh-topview {
  width: 100%;
  height: 45px;
  padding-left: 20px;
  padding-right: 20px;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  ::v-deep.el-select {
    width: 200px !important;
  }
  .topview-pici {
    // width: 500px;
    margin-left: 10px;
    // background-color: aqua;
    line-height: 30px;
    display: flex;
    .topview-pici-title {
      min-width: 80px;
      height: 36px;
      line-height: 36px;
      text-align: end;
      padding-right: 10px;
    }
    .el-select {
      width: 300px;
    }
  }
  .topview {
    .el-select {
      width: 120px !important;
    }
  }
}
// 头部添加
.action-bar {
  width: 100%;
  height: 50px;
  background-color: #00485a;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: end;
  -ms-flex-pack: end;
  justify-content: flex-end;
  margin-bottom: 10px;
  .btn-list {
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    .btn-item {
      margin-right: 15px;
    }
  }
}
::v-deep .el-dialog__wrapper {
  .el-dialog {
    // width: 50% !important;

    // width: 55% !important;
    min-width: 55%;
    .el-dialog__body {
      .el-form {
        .checkbox {
          // background: #00000000;
          display: block;
          .el-form-item__content {
            width: 95%;
            margin-left: 5%;
            position: relative;
            .checkboxck {
              position: absolute;
              top: 20px;
              left: 22px;
              // .el-button {
              // }
              .el-button--medium {
                padding: 0;
              }
            }
            .el-checkbox__input.is-indeterminate {
              .el-checkbox__inner {
                background-color: rgba(0, 110, 145, 1);
                border-color: rgba(0, 110, 145, 1);
              }
              .el-checkbox__label {
                color: rgba(0, 110, 145, 1);
              }
            }
            .el-checkbox.is-checked {
              .el-checkbox__inner {
                background-color: rgba(0, 110, 145, 1);
                border-color: rgba(0, 110, 145, 1);
              }
              .el-checkbox__label {
                color: rgba(0, 110, 145, 1);
              }
            }
            .checkbox-group {
              padding-left: 66px;
              min-height: 120px;
              overflow-y: auto;
              .el-checkbox {
                padding: 2px 10px;
                border: 1px solid rgba(220, 223, 230, 1);
                border-radius: 5px;
                margin-bottom: 10px;
              }
              .el-checkbox.is-checked {
                border: 1px solid rgba(0, 110, 145, 1);
                .el-checkbox__label {
                  color: rgba(0, 110, 145, 1);
                }
              }
            }
          }
        }
      }
    }
  }
}
// 溯源码
.codeview {
  ::v-deep .el-dialog {
    width: 25% !important;
    height: 40vh !important;
    .codeview-box {
      width: 100%;
      height: 15vh;
      display: flex;
      align-items: center;
      p {
        width: 30%;
        white-space: nowrap;
      }
      .el-input {
        // width: 90%;
        font-size: 18px;
      }
      .el-input-number--medium {
        width: 100%;
      }
    }
  }
}
::v-deep .el-upload--picture-card {
  width: 40px;
  height: 40px;
  background-color: rgba(255, 255, 255, 0.1);
  border: 1px solid #6ecae3;
}
::v-deep .el-upload--picture-card {
  position: relative;
}
::v-deep .el-upload--picture-card .el-icon-plus {
  font-size: 34px;
  color: #6ecae3;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
::v-deep .el-dialog__body {
  text-align: center;
}
.el-upload__tip {
  font-size: 12px;
  color: #606266;
  margin-top: 7px;
  position: absolute;
  width: 150px;
}
// 禁用样式
::v-deep .el-checkbox-button.is-disabled.is-checked {
  .el-checkbox-button__inner {
    color: #fff !important;
    background-color: #409eff80 !important;
    border-color: #409eff80 !important;
    -webkit-box-shadow: -1px 0 0 0 #409eff80 !important;
    box-shadow: -1px 0 0 0 #409eff80 !important;
  }
}
// 操作按钮 宽度统一
.traceCodeIcon {
  width: 130px;
  padding: 10px 15px;
  margin-bottom: 5px;
}
::v-deep .el-dialog {
  margin-top: 10vh !important;
  height: 60vh !important;
  .el-dialog__body {
    .el-table {
      // 解决行无法铺满整个表格
      .el-table__body {
        height: auto;
        // position: absolute;
        tr.current-row > td {
          background-color: #84c6d9;
        }
      }
      max-height: 40vh !important;
      overflow-y: auto;
      background-color: rgba(255, 255, 255, 1);
      .cell {
        color: #343434;
      }
      th {
        background-color: #c6dae1;
      }
      .el-input__inner {
        // border-right: none;
        padding: 0 5px;
      }
      .el-date-editor {
        .el-input__inner {
          // border-right: none;
          padding: 0 20px;
        }
        .el-input__prefix {
          left: 0;
        }
        .el-input__suffix {
          right: 0;
        }
      }
      .el-table__row {
        background-color: #ffffff;
      }
      .el-table__row--striped {
        background-color: #c6dae1;
      }
      th.is-leaf {
        border-color: rgba(77, 77, 77, 1);
        border: none;
      }
      td {
        border-color: rgba(77, 77, 77, 1);
        border: none;
      }
      tr:hover {
        background-color: #84c6d9 !important;
      }
      .el-table__empty-text {
        color: #343434;
      }
      .current-row {
        // background-color: rgb(177, 177, 177);
        background-color: #dbdbdb !important;
      }
      // color: #343434;
    }
    .el-table--border {
      border-color: rgba(77, 77, 77, 1);
      border: none;
      border-top-left-radius: 8px;
      border-top-right-radius: 8px;
    }
  }
}
::v-deep .zhcontent {
  .el-table {
    width: 87vw;
    height: 90% !important;
    .el-table__body-wrapper {
      height: 100% !important;
    }
  }
}
</style>
